package xin.ryven.car.android.lyrics

data class LrcEntry(
    val time: Long,  // 歌词时间，毫秒
    val text: String // 歌词文本
) {
    companion object {
        fun parseLrc(lrcText: String): List<LrcEntry> {
            val entries = mutableListOf<LrcEntry>()
            val lines = lrcText.split("\n")
            
            val timeRegex = "\\[(\\d{2}):(\\d{2})\\.(\\d{2,3})](.*)".toRegex()
            
            lines.forEach { line ->
                timeRegex.matchEntire(line)?.let { matchResult ->
                    val (min, sec, ms, text) = matchResult.destructured
                    val time = (min.toLong() * 60 * 1000) +
                            (sec.toLong() * 1000) +
                            (ms.padEnd(3, '0').toLong())
                    entries.add(LrcEntry(time, text.trim()))
                }
            }
            
            return entries.sortedBy { it.time }
        }
    }
} 